package cn.rui.controller;

import cn.rui.aspects.Log;
import cn.rui.common.Result;
import cn.rui.pojo.vo.PageResult;
import cn.rui.service.ImgFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 文件上传下载
 *
 * @author 徽州大都督
 * @date 2021/05/18
 */
@RestController
@RequestMapping("img")
public class ImgController {

    @Autowired
    private ImgFileService imgFileService;

    @PostMapping("findPage")
    public Map findPage(@RequestBody PageResult pageResult) {

        return imgFileService.findPage (pageResult);
    }

    //上传图片
    @PostMapping("upload")
    @Log("上传图片")
    public Result upload(MultipartFile file) {
        return imgFileService.upload (file);
    }

    //删除图片
    @DeleteMapping("deleteById/{id}")
    @Log("删除图片")
    public Result deleteById(@PathVariable("id") Integer id) {
        return imgFileService.deleteById(id);
    }

    //查询全部图片
    @GetMapping("findAll")
    public Result findAll(){
        return imgFileService.findAll();
    }
}
